<?php
/**
 * 社宅物件検索用SQL作成クラス<br />
 *
 * @package apamanshop
 * @author SS永田
 * @copyright 
 */
class Rstobi_Model_SyatakuSearch extends Rstobi_Model_Base
{
    /**
     * 社宅物件検索用SELECT句取得
     * 
	 * @access	public
	 * @return  string
     */
	public function getSelectForSyataku($params)
	{
		// 社宅控除率取得
		$shatakuKoujyoritsu = $this->_model_rstobi_common->getShatakuKoujyoritsu($params);
		
		$strSelect  = ' ,CASE';
		$strSelect .= '    WHEN T03.T03_SHATAKU_TEKIYOU_FLAG = 1';
		$strSelect .= '    AND (T03.T03_TORIHIKI_TAIYOU = 1 OR T03.T03_TORIHIKI_TAIYOU = 9) THEN 100';
		$strSelect .= '    WHEN T03.T03_SHATAKU_TEKIYOU_FLAG = 1';
		$strSelect .= '    AND M05.M05_SHATAKU_KOUJYORITSU <= '.$shatakuKoujyoritsu;
		$strSelect .= '    AND T03.T03_TORIHIKI_TAIYOU <> 1 AND T03.T03_TORIHIKI_TAIYOU <> 9 THEN M05.M05_SHATAKU_KOUJYORITSU';
		$strSelect .= '    WHEN T03.T03_SHATAKU_TEKIYOU_FLAG = 1';
		$strSelect .= '    AND M05.M05_SHATAKU_KOUJYORITSU > '.$shatakuKoujyoritsu;
		$strSelect .= '    AND T03.T03_TORIHIKI_TAIYOU <> 1 AND T03.T03_TORIHIKI_TAIYOU <> 9 THEN '.$shatakuKoujyoritsu;
		$strSelect .= '    ELSE 0';
		$strSelect .= ' END AS M05_SHATAKU_KOUJYORITSU';
		
		return $strSelect;
	}
	
    /**
     * 社宅物件検索用From句取得
     * 
	 * @access	public
	 * @return  string
     */
	public function getFromForSyataku()
	{
		$strFrom  = ' ,M05TENPO_INFO M05';
		
		return $strFrom;
	}
	
    /**
     * 社宅物件検索用Where句取得
     * 
	 * @access	public
	 * @return  string
     */
	public function getWhereForSyataku()
	{
		// Where句用変数
		$strWhere  = ' AND M05.M05_KOUKAI_FLAG = 1';
		$strWhere .= ' AND M05.M05_SHATAKU_USE_FLAG = 1';
		$strWhere .= ' AND M05.M05_SHATAKU_KAISHIBI <= TO_DATE(SYSDATE)';
		$strWhere .= ' AND M05.M05_TENPO_CD = T03.T03_TENPO_CD';
		
		return $strWhere;
	}
}
?>